<?php
namespace app\api\controller;
use app\common\authtoken\token;

use think\Controller;

/**
 * 用户授权
 */
class Authbase extends Controller
{
    //构造方法
    public function _initialize()
    {
        $sign=input('sign');
        $client_token=input('client_token');
        if(empty($client_token)||empty($sign)){
            exit(json_encode(['statusCode'=>400,'msg'=>'token验证失败','sign'=>$sign,'client_token'=>$client_token]));  // 拒绝访问
        }
                
        $rankToken=new token();
        $sign_server=$rankToken ->getToken($client_token);

        $useMode=model('WechatUserModel')->where(['token'=>$client_token])->find();
        /*if(!$useMode)
        {
            $useMode=model('WechatUserModel')->where(['token'=>$client_token])->find();
        }*/

        //var_dump($sign . '||' . $sign_server);die;
        if(!$useMode)
        {
            exit(json_encode(['statusCode'=>400,'msg'=>'token验证失败','sign'=>$sign,'severtoken'=>$sign_server,'client_token'=>$client_token]));  // 拒绝访问
        }
        if ($sign != $sign_server) {            
            exit(json_encode(['statusCode'=>400,'msg'=>'sign验证失败','sign'=>$sign,'severtoken'=>$sign_server]));  // 拒绝访问
        }
        $this->useMode=$useMode;
        $this->Auth_Wxuser_Id=$useMode['id'];
        $this->Auth_Wxuser_name=$useMode['nick_name'];
        $this->Auth_Wxuser_avatar=$useMode['avatar_url'];
        $this->Auth_Wxuser_OpenId = $useMode['openid'];
        $this->Auth_Wxuser_OriginalId = $useMode['original_id'];
    }
}